home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
basic
/
iqb9107.zip
/
READMCBS.BAS
< prev
Wrap
BASIC Source File
|
1991-06-27
|
3KB
|
130 lines
' ReadMCBs.Bas
' Program to display the DOS memory control block chain
' $INCLUDE: 'QB.BI'
CONST FALSE = 0, TRUE = NOT FALSE
DECLARE SUB GetFirstMCB ()
DECLARE SUB GetNextMCB ()
DECLARE SUB PrintOwnerName ()
DECLARE FUNCTION LZPadStr$ (N$, pLen%)
DIM SHARED Regs AS RegTypeX
DIM SHARED MCBSeg AS SINGLE
DIM SHARED ReservedStuff%(11)
' Get the PSP address of the program running
' (If you're running this in the environment, then the PSP
' belongs to QB; if you've compiled ReadMCBs, then it's
' ReadMCBs' PSP.
Regs.ax = &H5100
InterruptX &H21, Regs, Regs
PSP% = Regs.bx
PRINT "The PSP of this program is "; HEX$(PSP%)
PRINT
PRINT " Segment owner Size"
PRINT " Address PSP par. Reserved Area";
PRINT " Name"
PRINT "--------- ----- ---- --------------------------------";
PRINT " --------"
GetFirstMCB
' Loop through the memory control blocks,
' printing out detail for each
DO WHILE MCBSeg <> 0
GetNextMCB
LOOP
PRINT "--------- ----- ---- --------------------------------";
PRINT " --------"
' All done
END
SUB GetFirstMCB
' Subprogram to get the segment address of the first
' memory control block, using the undocumented DOS
' function GetListOfLists (Int 21h, AH = 52h)
Regs.ax = &H5200
InterruptX &H21, Regs, Regs
MCBPtrSeg% = Regs.es
MCBPtrOff% = Regs.bx - 2
DEF SEG = MCBPtrSeg%
MCBSeg = PEEK(MCBPtrOff%) + PEEK(MCBPtrOff% + 1) * 256!
DEF SEG
END SUB
SUB GetNextMCB
' Subprogram to get the segment address of the next
' memory control block, and print out its detail.
Marker% = 0
Owner = 0
Size = 0
DEF SEG = MCBSeg
Marker% = PEEK(0)
Owner = PEEK(1) + PEEK(2) * 256!
Size = PEEK(3) + PEEK(4) * 256!
FOR I% = 1 TO 11
ReservedStuff%(I%) = PEEK(4 + I%)
NEXT I%
DEF SEG
Marker$ = CHR$(Marker%)
PRINT LZPadStr$(HEX$(MCBSeg), 4); ":0000 ";
PRINT LZPadStr$(HEX$(Owner), 4); " ";
PRINT LZPadStr$(HEX$(Size), 4); " ";
FOR I% = 1 TO 11
PRINT LZPadStr$(HEX$(ReservedStuff%(I%)), 2); " ";
NEXT I%
IF MCBSeg < Owner AND MCBSeg + Size > Owner THEN
PrintOwnerName
END IF
IF Marker$ = "M" THEN MCBSeg = MCBSeg + (Size + 1)
IF Marker$ = "Z" OR Marker$ <> "M" THEN MCBSeg = 0
IF Marker$ <> "M" AND Marker$ <> "Z" THEN
PRINT " Memory chain error!!"
ELSE
PRINT ""
END IF
END SUB
SUB PrintOwnerName
' Subroutine to print the MCB owner's name
GotName% = FALSE
J% = 0
Owner$ = ""
WHILE NOT GotName%
J% = J% + 1
Ch% = ReservedStuff%(3 + J%)
IF Ch% = 0 THEN GotName% = TRUE
IF NOT GotName% THEN Owner$ = Owner$ + CHR$(Ch%)
IF J% = 8 THEN GotName% = TRUE
WEND
PRINT Owner$;
END SUB
FUNCTION LZPadStr$ (N$, pLen%)
' Function to return a copy of the numeric string N$,
' padded on the left with pLen% zeroes.
LZPadStr$ = STRING$(pLen% - LEN(N$), "0") + N$
END FUNCTION